package com.example.module_home.adapter

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.module_home.R
import com.example.module_home.entity.HouseEntity
import com.example.module_home.vm.HouseViewModel

class HouseAdapter(vm: HouseViewModel) :BaseQuickAdapter<HouseEntity,BaseViewHolder>(R.layout.house_item) {
    lateinit var vm:HouseViewModel
    init {
        this.vm=vm
    }
    override fun convert(holder: BaseViewHolder, item: HouseEntity) {
        val house = holder.getView<TextView>(R.id.house_name)
        val qy = holder.getView<TextView>(R.id.house_qy)
        val area = holder.getView<TextView>(R.id.house_area)

        house.text=item.regionName
        qy.text=item.enterpriseName
        area.text="${item.area}m²"

        val tv = holder.getView<TextView>(R.id.house_status)
        if (item.rented){
            tv.text="已出租"
            tv.setBackgroundResource(com.example.lib_resource.R.color.chartreuse)
        }else{
            tv.text="未出租"
            tv.setBackgroundResource(com.example.lib_resource.R.color.cyan)
        }
    }
}